package com.seaking.dao;

import com.seaking.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * Created by wchha on 10/24 0024.
 */
@Repository
public class LoginDao {

    @Autowired
    private HibernateTemplate hibernateTemplate;


    public Admin check(Admin admin) {
        List<?> list = hibernateTemplate.find("from com.seaking.pojo.Admin a where a.userName = ? and a.passWord = ?", admin.getUserName(), admin.getPassWord());
        if (list.size() > 0) return (Admin) list.get(0);
        return null;
    }

    public List checkUserName(String userName) {
        List<?> list = hibernateTemplate.find("from com.seaking.pojo.Admin where userName = ?", userName);
        return list;
    }

    @Transactional
    public void addAdmin(Admin admin) {
        hibernateTemplate.save(admin);
    }
}
